package web.wicketLife;

import org.apache.wicket.Component;
import org.apache.wicket.Session;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import aplicacion.SesionPersonalizada;

public class WicketLifeHome extends WebPage{

	private static final long serialVersionUID = 1L;
	private Integer cont = 0;

	public WicketLifeHome() {
		add(
			texto(),
			boton(),
			labelBegins(),
			labelEnds()
		);
	}

	private Component labelEnds() {
		IModel<Integer> modelo = new PropertyModel<Integer>((SesionPersonalizada)Session.get(), "ends");
		return new Label("request_ends", modelo);
	}

	private Component labelBegins() {
		IModel<Integer> modelo = new PropertyModel<Integer>((SesionPersonalizada)Session.get(), "begins");
		return new Label("request_begins", modelo);
	}

	protected Label texto() {
		return new Label("texto", new PropertyModel<Integer>(this, "cont"));
	}

	private Component boton() {
		return new AjaxLink<Void>("boton") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick(AjaxRequestTarget target) {
				cont++;
				setResponsePage(getPage());
			}
		};
	}


	//setters&getters
	public void setCont(Integer cont) {
		this.cont = cont;
	}

	public Integer getCont() {
		return cont;
	}
}